package cn.aitrox.ry.service.auth.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.auth.dao.AuthPermissionResourceDao;
import cn.aitrox.ry.service.auth.entity.AuthPermissionResourceEntity;
import cn.aitrox.ry.service.auth.mapper.AuthPermissionResourceMapper;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class AuthPermissionResourceDaoImpl extends BaseDaoImpl<AuthPermissionResourceEntity> implements AuthPermissionResourceDao {

    @Autowired
    private AuthPermissionResourceMapper mapper;

    @Override
    public void batchInsert(List<AuthPermissionResourceEntity> list) {
        batchInsert(list, 1000, new MapperSqlCallback<AuthPermissionResourceEntity>() {
            @Override
            public void batchInsert(List<AuthPermissionResourceEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public void deleteByPermissionIdResourceIds(Integer permissionId, List<Integer> resourceIds) {
        mapper.deleteByPermissionIdResourceIds(permissionId, resourceIds);
    }

    @Override
    public List<AuthPermissionResourceEntity> findByPermissionIds(List<Integer> permissionIds) {
        if (ArrayUtil.isEmpty(permissionIds)) {
            return new ArrayList<>();
        }
        return mapper.findByPermissionIds(permissionIds);
    }
}
